package com.tjh.spring5.testdemo;

import com.tjh.spring5.config.TxConfig;
import com.tjh.spring5.service.UserService_day31;
import com.tjh.spring5.service.UserService_day33;
import com.tjh.spring5.service.UserService_day34;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class TransactionalTest {

    // day31
    @Test
    public void testAccount1() {
        ApplicationContext context =
                new ClassPathXmlApplicationContext("beanday31.xml");
        UserService_day31 userService = context.getBean("userService_day31", UserService_day31.class);
        userService.accountMoney();
    }

    /**
     * day33：
     *      测试：注释 TxConfig 类的 getDataSourceTransactionManager(DataSource dataSource) 方法后执行
     */
    @Test
    public void testAccount2() {
        ApplicationContext context =
                new ClassPathXmlApplicationContext("beanday31.xml");
        UserService_day33 userService = context.getBean("userService_day33", UserService_day33.class);
        userService.accountMoney();
    }

    // day34
    @Test
    public void testAccount3() {
        ApplicationContext context =
                new ClassPathXmlApplicationContext("beanday34.xml");
        UserService_day34 userService = context.getBean("userService_day34", UserService_day34.class);
        userService.accountMoney();
    }

    /**
     * day35
     *      测试：解开 TxConfig 类的 getDataSourceTransactionManager(DataSource dataSource) 方法后执行
     */
    @Test
    public void testAccount4() {
        ApplicationContext context =
                new AnnotationConfigApplicationContext(TxConfig.class);
        UserService_day33 userService = context.getBean("userService_day33", UserService_day33.class);
        userService.accountMoney();
    }

}


